package daili.jsdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.function.Consumer;

public class SimpleInvocationHandler implements InvocationHandler {

	private Object realObj;
	
	private Consumer<Object> cs = System.out::println;
	
	// 真实对象注入
	public SimpleInvocationHandler(Object realObj) {
		this.realObj = realObj;
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		cs.accept("invoke method.name=" + method.getName());
		
		// 调用真实对象的方法
		Object result = method.invoke(realObj, args);
		cs.accept("invode result=" + result);
		
		cs.accept("end invoke.");
		
		return result;
	}

}
